package com.jio.service.impl;

import com.jio.entity.Role;
import com.jio.mapper.RoleMapper;
import com.jio.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Override
    public List<Role> findAll() {
        return roleMapper.findAll();
    }

    @Override
    public void add(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public void deleteById(int id) {
        roleMapper.deleteById(id);
    }

    @Override
    public void deleteIds(List<Integer> ids) {
        for (int id : ids) {
            roleMapper.deleteById(id);
        }
    }

    @Override
    public Role findRole_Permission(int id) {
        return roleMapper.selectRole_Permission(id);
    }

    @Override
    public int edit(Role role) {
        return roleMapper.update(role);
    }

    @Override
    @Transactional
    public void editPermission(int rid, List<Integer> ids) {
        roleMapper.deleteR_P(rid);
        roleMapper.insertR_P(rid,ids);
    }
}
